package com.loie.xcx.comm;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理类
 *
 * @author zhl
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonResult<String> error(Exception e) {
        e.printStackTrace();
        return new JsonResult<>(500, "系统错误");
    }

    /**
     * 自定义处理类
     */
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public JsonResult<String> error(CustomException e) {
        e.printStackTrace();
        return new JsonResult<>(e.getCode(), e.getErrorMessage());
    }
}

